package io.nio;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * 使用nio 对文件进行读写
 */
public class NioFileWR {
    public static void main(String[] args) {
        try {
            // 写入文件（追加方式：StandardOpenOption.APPEND）
            Files.write(Paths.get("G://test.txt"),"测试数据".getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
            byte[] bytes = Files.readAllBytes(Paths.get("G://test.txt"));
            System.out.println(new String(bytes,StandardCharsets.UTF_8));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
